<?php
class Admin_Model_DbTable_Permission extends Zend_Db_Table_Abstract {
	protected $_name = 'permission';
	public function addPermission($role_id, $table_name, $status) {
		$data = array (
				'ROLE_ID' => $role_id,
				'TABLE_NAME' => $table_name,
				'STATUS' => $status 
		);
		return $this->insert ( $data );
	}
	public function updateStatus($id, $status) {
		$data = array (
				'STATUS' => $status 
		);
		return $this->update ( $data, "ID = $id" );
	}
	public function updatePermission($id, $role_id, $table_name, $status) {
		$data = array (
				'ROLE_ID' => $role_id,
				'TABLE_NAME' => $table_name,
				'STATUS' => $status 
		);
		return $this->update ( $data, "ID = $id" );
	}
	public function removePermission($id) {
		return $this->delete ( "ID = $id" );
	}
	public function getAllPermission() {
		return $this->fetchAll ( "STATUS = 1" )->toArray();
	}
	public function getTableByRole($role_id, $status) {
		return $this->fetchAll("ROLE_ID = $role_id AND STATUS = $status")->toArray();
	}
	public function getPermissionById($id, $status) {
		return $this->fetchRow("ID = $id AND STATUS = $status")->toArray();
	}
}

